cancel_selector = "##{element_form_id(:action => :update)} a.cancel".to_json

if controller.send :successful?
  page << "$$(#{cancel_selector}).first().link.close_with_refresh();"
  page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?}
else
  page << "l = $$(#{cancel_selector}).first().link;"
  page.replace element_form_id(:action => :update), :partial => 'update_form'
  page << "l.register_cancel_hooks();"
end